// NACL MOD TRACK "third_party/nacl-glibc/sysdeps/nacl/mmap.c"

#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>

#include <irt_syscalls.h>


void *__mmap(void *addr, size_t len, int prot, int flags,
           int fd, off_t offset) {
  ENOSYS_IF_NULL(__nacl_irt_mmap)

  int64_t nacl_offset = (int64_t) offset;
  int result = __nacl_irt_mmap (&addr, len, prot, flags, fd, nacl_offset);
  if (result != 0) {
    errno = __nacl_abi_errno_to_errno(result);
    return MAP_FAILED;
  }
  return addr;
}

weak_alias (__mmap, mmap)
